package user.action;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import user.bean.UserBean;
import user.factory.UserFactory;
import user.service.UserService;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class UserLoginAction extends ActionSupport implements SessionAware{
	private UserBean user;
	private  Map session;
	
	public Map getSession(){
		return session;
	}
	@Override
	public void setSession(Map session){
		this.session=session;
	}
	
	public UserBean getUser() {
		return user;
	}

	public void setUser(UserBean user) {
		this.user = user;
	}
	
	@SuppressWarnings("unchecked")
	public String login() throws Exception {	
		UserBean userbean = new UserBean();
    	UserService userdao = UserFactory.getInstance().createUserService();
		userbean.setUsername(user.getUsername());
		userbean = userdao.Login(userbean);
		if (userbean != null
				&& userbean.getPassword().equalsIgnoreCase(user.getPassword())) {
			this.session.put("user", userbean);
			return SUCCESS;
		} else {
			this.addActionError("登陆错误");
			return INPUT;
		}
	}
	

}
